package messages;

import static org.junit.Assert.*;

import org.junit.Test;

public class GeneralAckTest {

	@Test
    public void testDataConstructor()
    {
        byte[] data = new byte[] {MessageType.GeneralAck.getIdentifier(), MessageType.DeregistrationMessage.getIdentifier(), 1};
        GeneralAck mess = new GeneralAck(data);
        assertEquals(MessageType.DeregistrationMessage, mess.getAckMessageType());
        assertTrue(mess.getSuccess());
    }
    
	@Test
    public void testDataConstructorFail()
    {
        byte[] data = new byte[] {MessageType.GeneralAck.getIdentifier()};
        
        try
        {
            new GeneralAck(data);
            fail();
        }
        catch (RuntimeException ex) {}
    }
    
	@Test
    public void testToArray()
    {
        GeneralAck mess = new GeneralAck(MessageType.DeregistrationMessage, true);
        byte[] result = mess.toByteArray();
        assertEquals(3, result.length);
        assertEquals(MessageType.GeneralAck.getIdentifier(), result[0]);
        assertEquals(MessageType.DeregistrationMessage.getIdentifier(), result[1]);
        assertEquals(1, result[2]);
    }
    
	@Test
    public void testGetSize()
    {
        GeneralAck mess = new GeneralAck(MessageType.DeregistrationMessage, true);
        assertEquals(3, mess.getMessageSize());
    }
    
	@Test
    public void testGetMessageType()
    {
        GeneralAck mess = new GeneralAck(MessageType.DeregistrationMessage, true);
        assertEquals(MessageType.GeneralAck, mess.getMessageType());
    }
    
	@Test
    public void testGetAckType()
    {
        GeneralAck mess = new GeneralAck(MessageType.CurrentStateMessage, true);
        assertEquals(MessageType.CurrentStateMessage, mess.getAckMessageType());
        
        mess = new GeneralAck(MessageType.CurrentPeopleStateRequest, true);
        assertEquals(MessageType.CurrentPeopleStateRequest, mess.getAckMessageType());
        
        mess = new GeneralAck(MessageType.RegisterHallCallMessage, true);
        assertEquals(MessageType.RegisterHallCallMessage, mess.getAckMessageType());
    }
    
	@Test
    public void testGetSuccess()
    {
        GeneralAck mess = new GeneralAck(MessageType.DeregistrationMessage, true);
        assertTrue(mess.getSuccess());
        assertEquals(1, mess.toByteArray()[2]);
        
        mess = new GeneralAck(MessageType.DeregistrationMessage, false);
        assertFalse(mess.getSuccess());
        assertEquals(0, mess.toByteArray()[2]);
    }

}
